function checkForm(form) {
	var elements = form.elements;
	for(var i = 0, n = elements.length; i < n; i++) {
		var element = elements[i];
		var pattern = element.getAttribute("pattern");
		if(pattern !== null) {
			var value = element.value;
			// TODO: it need exception if pattern is not correct 
			var regExp = new RegExp(pattern);
			if(!regExp.test(value)) {
				var message = element.getAttribute("message");
				if(message !== null) {
					alert(message);
				} else {
					var message = "Значение \"" + value + "\"\n";
					message += "не удовлетворяет шаблону \"" + pattern + "\"";
					alert(message);
				}
				return false;
			}
		}
	}
	return true;
}

function checkFormEditPass(form, pass) {
	if (form.password.value != form.passwordrep.value) {
		alert("Введенные пароли не совпадают");
		return false;
	}
	return true;
}


function submitForm(formId) {
	var form = document.getElementById(formId);
	if(form !== null) {
		if(checkForm(form)) {
			form.submit();
		}
	}
}

function resetForm(formId) {
	var form = document.getElementById(formId);
	if(form !== null) {
		form.reset();
	}
}

function openElementAccess(form){
	var elements = document.getElementById(form).elements;
	for(var i = 0, n = elements.length; i < n; i++) {
		elements[i].disabled=false;
	}
}